home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 6 / CU Amiga Magazine's Super CD-ROM 06 (1996)(EMAP Images)(GB)(Track 1 of 4)[!][issue 1997-01].iso / imagine / extras / tools / iiutilities / stageframes < prev    next >
Text File  |  1995-01-14  |  7KB  |  157 lines

  1. /*\
  2.  *
  3.  *  This ARexx script increases the number of frames in an animation
  4.  *  and scales the bars automaticly to fit the new animation length.
  5.  *  Produces a smoother and younger looking animation. :-)
  6.  *
  7.  *  Usage: StageExpand <stageFileName> <multiplier> [EXPAND]
  8.  *    stageFileName is renamed to stageFileName.old for backup.
  9.  *    Multiplier should be a whole number greater than one.
  10.  *    It tells the script how many times to enlarge your staging
  11.  *    file.  A two will double the number of frames, a three will
  12.  *    tripple them.
  13.  *    EXPAND is an optional but important switch.  Normally a bar with
  14.  *    a size of one frame is meant to be a cut.  Expanding it would
  15.  *    give strange results.  For instance, take the timeline below...
  16.  *
  17.  *       Frame     1  ... 10    ...    20 21 ... 30
  18.  *       Position: #########           ## #########
  19.  *
  20.  *    In this, the object stops at frame 10, and at frame 20 it jumps
  21.  *    and then moves from 21 to 30.  If the single frame at 20 were
  22.  *    to be expanded, it would stop at 10 and at frame 20, MOVE from
  23.  *    it's position at 10 to the new position at 20 and then move again
  24.  *    as it follows the third bar.  In this (and most) cases you want a
  25.  *    single bar to stay single.  But sometimes you might want the
  26.  *    script to expand them anyway.  Include the EXPAND keyword at the
  27.  *    end expand single frames.  Note that the first bar in a row of
  28.  *    bars will not be expanded since the first bar should always be a
  29.  *    single frame.  How do you tween a position with no start?
  30.  *
  31.  *  Notes:
  32.  *      Each object is given a line of its own in the output.  A "." is
  33.  *    displayed for each timeline bar that is modified.
  34.  *      This script is good for increasing animation lengths, obviously.
  35.  *    Sometimes you just want to make that 1 second flying logo into
  36.  *    a 3 second logo easily.  But even beter is for doing motion
  37.  *    blur.  Use a value of 8 to increase the length 8x times and then
  38.  *    use an image processing program to merge the frames.  The way I
  39.  *    think of motion bluring is to consider each set of 8 frames to be
  40.  *    a single frame.  The camera shutter opens at frame 1, and closes
  41.  *    at frame 8, to repeat with the next group of 9 to 16.
  42.  *      You can not reduce the animation length with this program.  I
  43.  *    thought about it, but a problem comes up when you have a long row
  44.  *    or even just two 1 frame action bars.  What to do.. merge them?
  45.  *    Randomly delete one tor two or more?  Depending on how the anim
  46.  *    was set up, merging might work, or make a big mess. If you really
  47.  *    want to reduce an animation size you can use the range command to
  48.  *    generate a subset.  The problem is that does not always produce a
  49.  *    smooth animation.  If you want to cut an animation dowm from 30
  50.  *    to 15 you simply render every 2nd frame.  But if you want a 20
  51.  *    frame anim instead, you have to render every 2.5 frames.  So when
  52.  *    you approximate and render frame 3 instead of 2.5, you get a jump
  53.  *    in the anim.  The solution is to expand the animation.  In the
  54.  *    above example, just expand it to a 60 frame animation and render
  55.  *    every 3rd frame.  That way it results in a nice, smooth animation.
  56.  *    The ReduceFrames can be used to figure out the smallest amount you
  57.  *    can increase the animation to and get a smooth animation.  If you
  58.  *    wanted to turn a 30 frame anim into a 24 frame anim, use ReduceFrames
  59.  *    and it will tell you to expand the anim by a factor of four and
  60.  *    render every 4th frame.
  61.  *      I hope that was clear. I'm a programmer not an english major. :)
  62.  *
  63.  *  V1.0 Nov-22-94
  64.  *  IanSmith@moose.erie.net
  65.  *
  66. \*/
  67.  
  68. Numeric Digits 14                    /* Need at least 12 to handle 32 bits */
  69. Parse Arg FileName Change ExpandToggle .
  70. If Change="" Then Do
  71.  Say "Usage: StageExpand <stageFileName> <multiplier> [EXPAND]"
  72.  Say "       More help can be found in the header of this file."
  73.  Exit
  74. End
  75.  
  76. If Upper(ExpandToggle)="EXPAND" Then Expand=1; Else Expand=0
  77. MaxFrames=0
  78. Temp="Temp$Stage."||Date(D)||Time(S)               /* Create temp filename */
  79. Address Command 'Delete >NIL:' FileName||".Old"    /* Erase backup file */
  80. If Open(Out,Temp,"W")=0 Then Do
  81.  Say "Can't open temp staging file!"
  82.  Exit
  83. End
  84. If Open(In,FileName,"R")=0 Then Do
  85.  Say "Can't find '"FileName"' to open!"
  86.  Exit
  87. End
  88. Call Open(Text,"*","W")
  89. Call WriteCH(Text,"Multiplying '"||FileName||"' by "||Change)
  90. Call ParseStaging(C2D(SubStr(ReadWrite(In,12),5,4)))
  91. Call WriteLN(Text,"") Close(In) Close(Out) Close(Text)
  92. Address Command 'Rename' FileName 'To' FileName||".Old"
  93. Address Command 'Rename' Temp 'To' FileName
  94.  
  95. Exit
  96.  
  97. ParseStaging: PROCEDURE EXPOSE Change Expand MaxFrames
  98.  Parse Arg MaxSize                             /* Recursive Function     */
  99.  TotalSize=4; New=0
  100.  Do Until TotalSize>=MaxSize                   /* Read MaxSize Bytes     */
  101.   LastName=Name
  102.   Name=ReadWrite(In,4)
  103.   If Name~=LastName Then New=0
  104.   Size=C2D(ReadWrite(In,4))
  105.   If Size//2=1 Then Size=Size+1                /* Add pad byte if needed */
  106.   If Name="ISTG" | Name="SOBJ" Then Do
  107.    TotalSize=TotalSize+ParseStaging(Size)+8    /* Parse into these hunks */
  108.    Iterate
  109.   End
  110.   TotalSize=TotalSize+Size+8                   /* Add SIZE and NAME length */
  111.   If Name="NAME" Then Do
  112.    Call WriteCH(Text,'0A'x||"Expanding "||ReadWrite(In,Size))
  113.    LastSF=-1; LastEF=-2
  114.   End; Else If Name="MAXF" Then Do
  115.    MaxFrames=C2D(ReadCH(In,Size))*Change
  116.    Call WriteCH(Out,Right(D2C(MaxFrames),2,'00'x))
  117.    LastSF=-1; LastEF=-2;
  118.   End; Else If Index("LOOP-NAME-STGF-LYR0", Name)=0 Then Do
  119.    Call WriteCH(Text,".")
  120.    Buffer=ReadCH(In,Size)
  121.    StartF=C2D(SubStr(Buffer,3,2))
  122.    EndF=C2D(SubStr(Buffer,5,2))
  123.    If (StartF>0 & StartF<=MaxFrames & EndF>0 & EndF<=MaxFrames & StartF<=EndF) Then Do
  124.     If (EndF-StartF=0) & (Expand=0 | New=0) Then Do       /* If single...   */
  125.      NewStartF=StartF*Change-(Change-1)                   /* ..don't expand */
  126.      NewEndF=EndF*Change-(Change-1)
  127.     End; Else Do
  128.      If (LastEF-LastSF=0 & LastEF+1=StartF) & (Expand=0 | New=1) Then
  129.       NewStartF=StartF*Change-(Change-1)*2
  130.      Else
  131.       NewStartF=StartF*Change-(Change-1)                      /* ...expand */
  132.      If EndF=1 Then
  133.       NewEndF=1
  134.      Else
  135.       NewEndF=EndF*Change
  136.     End
  137.     Buffer=Overlay(Right(D2C(NewStartF),2,'00'x),Buffer,3)
  138.     Buffer=Overlay(Right(D2C(NewEndF),2,'00'x),Buffer,5)
  139.     LastSF=StartF; LastEF=EndF; New=New+1
  140.    End; Else Do
  141.     Say "Hunk" Name "is not a valid timeline!"
  142.     LastSF=-1; LastEF=-2
  143.    End
  144.    Call WriteCH(Out,Buffer)
  145.   End; Else Do
  146.    Call ReadWrite(In,Size)
  147.    LastSF=-1; LastEF=-2
  148.   End
  149.  End
  150. Return TotalSize
  151.  
  152. ReadWrite:                                  /* This reads staging data,  */
  153.  Parse Arg FileHandle , Bytes .             /* writes it to the new file */
  154.  RWBuffer=ReadCH(FileHandle, Bytes)         /* and returns the data.     */
  155.  Call WriteCH(Out,RWBuffer)
  156. Return RWBuffer
  157.